package org.tagging.exceptionHandler;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.tagging.exception.UnSupportedConditionException;
import org.tagging.exception.UnSupportedLanguageException;
import org.tagging.utils.ResponseUtils;

@RestControllerAdvice
public class CommonException {

    @ExceptionHandler(UnSupportedLanguageException.class)
    public String unSupportedLanguageException(Exception e) {
        String build = ResponseUtils.build(HttpStatus.BAD_REQUEST.value(), e.getMessage());
        return ResponseUtils.buildJSONString(build);
    }

    @ExceptionHandler(UnSupportedConditionException.class)
    public String unSupportedConditionException(Exception e) {
        String build = ResponseUtils.build(HttpStatus.BAD_REQUEST.value(), e.getMessage());
        return ResponseUtils.buildJSONString(build);
    }

    @ExceptionHandler(UnsupportedOperationException.class)
    public String unsupportedOperationException(Exception e) {
        String build = ResponseUtils.build(HttpStatus.BAD_REQUEST.value(), e.getMessage());
        return ResponseUtils.buildJSONString(build);
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public String illegalArgumentException(Exception e) {
        String build = ResponseUtils.build(HttpStatus.BAD_REQUEST.value(), e.getMessage());
        return ResponseUtils.buildJSONString(build);
    }
}
